import 'package:flutter/material.dart';

/* 一段时间内逐渐改变其子组件的不透明度的 widget */
class OpacityStatic extends StatefulWidget {
  const OpacityStatic({super.key});

  @override
  State<OpacityStatic> createState() => _OpacityStaticState();
}

class _OpacityStaticState extends State<OpacityStatic> {
  double _opacity = 1.0;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.grey[100],
        border: Border.all(color: Colors.black, width: 1),
        borderRadius: BorderRadius.circular(6)
      ),
      width: double.infinity,
      height: 200,
      child: Column(
        children: [
          ElevatedButton(
            onPressed: () {
              setState(() {
                _opacity = _opacity == 1.0 ? 0.3 : 1.0;
              });
            },
            child: const Text('opacity')
          ),
          AnimatedOpacity(
            opacity: _opacity,
            duration: const Duration(seconds: 1),
            curve: Curves.easeInOut,
            child: Container(
              width: 100,
              height: 100,
              color: Colors.amber[200],
            ),
          )
        ],
      ),
    );
  }
}